<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue实现一个简单的计算器</title>
    <script src="../../js/vue.js"></script>
    <style>
        .cal {
            text-align: center;
            margin-top: 200px;
        }

        .cal button {
            width: 120px;
            height: 35px;
            background-color: #2aabd2;
        }

        .cal span {
            width: 120px;
            height: 35px;
            background-color: white;
        }

    </style>
</head>
<body>
<div id="app" class="cal">
    <button v-on:click="sub">-</button>
    <span>{{number}}</span>
    <button v-on:click="add">+</button>
</div>
</body>
<script>

    let app1 = new Vue({
        el: '#app',
        data: {
            number: 0
        },
        methods: {
            add: function () {
                if(this.number >= 10) {
                    console.log("最多只能为10个");
                    return;
                }
                this.number++;
            },
            sub: function () {
                if(this.number <= 0) {
                    console.log("最少只能为0个");
                    return;
                }
                this.number--;
            }
        }
    });

</script>
</html>